package chapter1.classTest.task;

import java.io.*;


/*
指定一个文件，统计其中其中的汉字数目
 */
public class Task5 {
    public static void main(String[] args) throws Exception {
        InputStream in = new FileInputStream("F:\\123\\1.txt");
        byte[] b = new byte[in.available()];
        int n = in.read(b);
        String s = new String(b, 0, n);
        s = s.replaceAll("[^\\u4e00-\\u9fa5]+", "");
        System.out.println(s);
        in.close();

        FileWriter out = new FileWriter("F:\\123\\2.txt");
        out.write(s);
        out.close();

        FileReader in2 = new FileReader("F:\\123\\2.txt");
        int n2 = 0;
        int count = 0;
        while ((n2 = in2.read()) != -1)
            count++;
        in2.close();

        System.out.println(count);


    }
}
